<template>
  <div class="right-container">
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>权限管理</el-breadcrumb-item>
      <el-breadcrumb-item>权限列表</el-breadcrumb-item>
    </el-breadcrumb>

    <!-- 权限列表卡片 -->
    <el-card class="box-card">
      <!-- 设置stripe实现隔行变色，对el-table单项=向绑定数据源rightsList -->
      <el-table :data="rightsList" stripe>
        <el-table-column type="index" label="#"></el-table-column>
        <el-table-column label="权限名称" prop="authName"></el-table-column>
        <el-table-column label="路径" prop="path"></el-table-column>
        <el-table-column label="权限等级" prop="level">
          <template slot-scope="scope">
            <!-- v-if根据作用域插槽传来的值scope中row对象下的level值判断使用哪种标签-->
            <el-tag v-if="scope.row.level === '0'">一级</el-tag>
            <el-tag type="success" v-else-if="scope.row.level === '1'">二级</el-tag>
            <el-tag type="danger" v-else>三级</el-tag>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script>
import { getRightsList } from '@/api/getRightsListApi.js'
export default {
  name: 'myRights',
  data () {
    return {
      // 权限列表数组
      rightsList: []
    }
  },
  methods: {
    // 获取权限列表函数
    async getRights () {
      const { data: res } = await getRightsList('list')
      if (res.meta.status !== 200) {
        return this.$notify.error({ title: '权限列表获取失败', message: res.meta.msg })
      }
      // 没有return出去则数据获取成功，将res中的数据合并到rightsList数组中
      this.rightsList = res.data
    }
  },
  created () {
    this.getRights()
  }
}
</script>

<style lang="less" scoped>

</style>
